# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  include AuthenticatedSystem
  
  before_filter :set_charset  
  before_filter :configure_charsets
  
  def set_charset  
    headers["Content-Type"] = "text/html; charset=utf-8"  
  end  
  
  def configure_charsets  
    response.headers["Content-Type"] = "text/html; charset=utf-8"  
    suppress(ActiveRecord::StatementInvalid) do  
      ActiveRecord::Base.connection.execute 'SET NAMES UTF8'  
    end  
  end
  
  def bbcode2html(text)
    text.gsub!(/\[code\]/i, "[code=ruby]")
    text.scan(/(\[code\=([a-z].+?)\](.+?)\[\/code\])/m).each do |match|
      text.gsub!(match[0],CodeRay.scan(match[2].strip, match[1].to_sym).div( :line_numbers => :table,:css => :class))
    end
    text = BBCodeizer.bbcodeize(text)
    text.gsub!(/\r\n/i, "<br/>")
    return "<br/>" + text
  end

end